#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time   : 2021/7/15 23:22
# @Author : cjw
from server_task.base.base_api import BaseApi
from server_task.setting import WEWORK_URL


class WeWorkApi(BaseApi):
	token: str = None
	base_url: str = WEWORK_URL

	def __init__(self):
		"""初始化就获取token"""
		if not self.token:
			self.token = self.get_token

	@property
	def get_token(self):
		"""
		获取token
		:return:
		"""
		# token请求数据
		# 具体的api对象通过这样的设计，可以实现数据化，为以后的自动化生成案例奠定了基础
		data = {
			'method': 'get',
			'url': f'{self.base_url}/gettoken',
			'params': {
				'corpid': 'ww4d7ee0e2d88be9cc',
				'corpsecret': 'cbednXXUNcE0uD7hddMRwP9Ih2fElev5unhF6I3VGIs'
			}
		}
		return self.request(data).json().get('access_token')
